package written.w20240908xiaohongshu.q3;

/**
 * Main
 *
 * @Author : Ruoyu Wang
 * @DateTime : 2024/9/8 15:10
 */

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static int f(int x) {
        return Integer.bitCount(x);
    }

    public static int g(int x) {
        int fx = f(x);
        int y = x + 1;
        while (f(y) != fx) {
            y++;
        }
        return y;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Set<Integer> notesSet = new HashSet<>();
        for (int num : a) {
            notesSet.add(num);
        }

        int maxLength = 0;
        for (int start : notesSet) {
            int length = 1;
            int next = g(start);

            while (notesSet.contains(next)) {
                length++;
                next = g(next);
            }

            maxLength = Math.max(maxLength, length);
        }

        System.out.println(maxLength);
        scanner.close();
    }
}
